{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3520c4b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你有以下wifi已经连接： ['HONOR 70', '2F-FPGA']\n",
      "请输入你想查看的wifi密码：HONOR 70\n",
      "wifi名字: HONOR 70 \n",
      "wifi密码: 12345678\n"
     ]
    }
   ],
   "source": [
    "from os import popen\n",
    "import re\n",
    "cmd_profile = 'netsh wlan show profile'\n",
    "user_profile = popen(cmd_profile).readlines()\n",
    "wifis = [i.strip().split(\":\")[-1].strip() for i in user_profile if re.match(\"\\s*所有用户配置文件\", i, re.I)]\n",
    "print(\"你有以下wifi已经连接：\", wifis)\n",
    "check_name = input(\"请输入你想查看的wifi密码：\")\n",
    "cmd_wifi = r'netsh wlan show profile ' + \"\\\"\" + check_name + \"\\\"\" + \" key=clear\"\n",
    "content = popen(cmd_wifi).readlines()\n",
    "if len(content) == 1:\n",
    "    print(content[-1])\n",
    "else:\n",
    "    password = [i.strip().split(\":\")[-1].strip() for i in content if re.match(\"\\s*关键内容\", i, re.I)][0]\n",
    "    print(\"wifi名字:\", check_name, \"\\nwifi密码:\", password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb2f757d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
